#pragma once
#include <map>
#include <windows.h>
#include <d3d11.h>
#include <D3DX11.h>
#include "resource.h"
#include <xnamath.h>
#include <vector>
#include "Shader.h"
#include "Camera.h"
#include "Timer.h"
#include "Geometry.h"
#include "vec.inl"

struct Application{

	Application(HINSTANCE hInstance, int nCmdShow, UINT width, UINT height );
	~Application();

	void LoadGeometry(Geometry* obj, GEOMETRY_TYPE type);
	void LoadCamera(const Camera& camera);
	int MainLoop();

private:

	static Application* app;
	static LRESULT CALLBACK MsgProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	HRESULT InitWindow();
	HRESULT InitDevice();
	HRESULT InitResource();

	void Render();
	//window
	HINSTANCE							m_hInst;
	int									m_nCmdShow;
	HWND								m_hWnd;
	UINT								m_width, m_height;
	//d3d device
	D3D_DRIVER_TYPE						m_driverType;
	D3D_FEATURE_LEVEL					m_featureLevel;
	ID3D11Device*						m_pDevice;
	ID3D11DeviceContext*				m_pImContext;
	IDXGISwapChain*						m_pSwapChain;
	//back buffer / depthstencil buffer
	ID3D11RenderTargetView*				m_pRenderTargetView;
	ID3D11Texture2D*					m_pDepthStencil;
	ID3D11DepthStencilView*				m_pDepthStencilView;

	//resources
	Shader								m_meshShader, m_lineShader;
	std::vector<Geometry*>				m_meshes, m_lines;
	ID3D11ShaderResourceView*			m_texView;
	//matrices of camera
	Camera								m_camera;
	//timer
	Timer								m_timer;
	//controller state
	bool								m_keysDown[256];
	vec<short, 2>						m_cursorPos, m_cursorPrePos;
	float								m_baseSpeed, m_speed, m_acc;
};
